//
//  DrawView.m
//  11-图形上下文状态栈
//
//  Created by J on 16/2/23.
//  Copyright © 2016年 J. All rights reserved.
//

#import "DrawView.h"

@implementation DrawView


- (void)drawRect:(CGRect)rect {
    // Drawing code
    //获取上下文
//    CGContextRef ref = UIGraphicsGetCurrentContext();//这个上下文的路径和path里面的上下文路径不同

    
//    UIBezierPath* path = [UIBezierPath bezierPath];
//    [path moveToPoint:CGPointMake(10, 125)];
//    [path addLineToPoint:CGPointMake(240, 125)];
//    path.lineWidth = 10;
//    path.lineCapStyle = kCGLineCapRound;
//    CGContextSaveGState(ref);//保存一份上下文状态 下次调用CGContextRestoreGState()可以恢复这句代码为止之前的状态
//
//    //路径添加到上下文
////    CGContextSetLineWidth(ref, 10);
//
////    CGContextAddPath(ref, path.CGPath);//CGPath UIKit路径转换为CoreGraphic的路径
//    [[UIColor orangeColor]set];//保存到图形上下文 两条线都变味这个颜色
//    [path stroke];
////    CGContextStrokePath(ref);
//
//    
//    UIBezierPath* path2 = [UIBezierPath bezierPath];
//    [path2 moveToPoint:CGPointMake(125 , 10)];
//    [path2 addLineToPoint:CGPointMake(125, 240)];
//    CGContextAddPath(ref, path2.CGPath);//CGPath UIKit路径转换为CoreGraphic的路径
//    [[UIColor purpleColor]set];//是保存到图形上下文中的 两条线都变为这个颜色
//
//    [path2 stroke];

//    CGContextRestoreGState(ref);//恢复保存的状态
//    CGContextStrokePath(ref);
//    CGContextSetLineCap(ref, kCGLineCapRound);
    
    
    CGContextRef ref = UIGraphicsGetCurrentContext();
    
    
    
    UIBezierPath* path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(10, 125)];
    [path addLineToPoint:CGPointMake(240, 125)];
//    path.lineWidth = 10;
    CGContextSaveGState(ref);
    CGContextSetLineWidth(ref, 10.0);
    path.lineCapStyle = kCGLineCapRound;
//    CGContextSaveGState(ref)
    CGContextAddPath(ref, path.CGPath);
    CGContextSetStrokeColorWithColor(ref, [UIColor orangeColor].CGColor);
//    [[UIColor orangeColor]set];
//    [path stroke];
    
    CGContextStrokePath(ref);
    
    
    UIBezierPath* path2 = [UIBezierPath bezierPath];
    [path2 moveToPoint:CGPointMake(125, 10)];
    [path2 addLineToPoint:CGPointMake(125, 240)];
    CGContextAddPath(ref, path2.CGPath);
//    path2.lineWidth = 10;
    path2.lineCapStyle = kCGLineCapRound;
    [[UIColor purpleColor]set];
//    [path2 stroke];
    CGContextRestoreGState(ref);
    
    CGContextStrokePath(ref);
    
    
    
    
    
    
    
    
}

@end
